// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import jquery from 'jquery'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import store from './store'
import "babel-polyfill"
import {getCookie} from "./util/cookie"

Vue.use(ElementUI)
Vue.config.productionTip = true

const MAIN_URL = 'http://localhost:7070'
// const MAIN_URL = 'http://122.114.5.206:7070'
Vue.prototype.$mainUrl = MAIN_URL
Vue.prototype.$post = function (url, data, okCb, errCb) {
  const loading = this.$loading({
    lock: true,
    text: '努力加载中...',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.9)'
  });
  if (data) {
    data = {request: JSON.stringify({data: data})}
  }
  jquery.ajax({
    type: "POST",
    url: MAIN_URL + url,
    dataType: 'json',
    headers: {
      'Access-Token':store.state.user.token
    },
    data: data,
    timeout: 20000,
    success: msg => {
      if (msg.response.success == true) {
        if (okCb)
          okCb(msg.response.data)
      } else {
        this.$message({message: '操作失败:' + msg.response.message, type: 'warning'})
      }
    },
    error: err => {
      this.$message({message: '操作失败!', type: 'warning'})
    },
    complete: res => {
      loading.close();
    }
  })
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})
